<?php
use yii\helpers\Html;
use mdm\admin\components\Helper;
use common\components\TGridView;
use yii\helpers\Url;
use yii\bootstrap\ActiveForm;
use common\helpers\TStringHelper;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('common', 'log');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="log-index">

    <?php
    $gridColumns = [
        [
            'name' => 'selectedIds',
            'class' => 'kartik\grid\CheckboxColumn',
            'checkboxOptions' => function($model, $key, $index, $column) {
                return [
                    'value' => $model->id,
                ];
            }
        ],
        [
            'class' => 'kartik\grid\SerialColumn',
            'header' => Yii::t('common','serial_number'),
        ],
        [
            'header'=> Yii::t('common', 'username'),
            'value' => function($model){
                return !empty($model->uid) ? \common\models\User::getUsernameByUid($model->uid) : '---';
            }
        ],
        [
            'header'=> Yii::t('common', 'channel'),
            'attribute' => 'channel',
        ],
        [
            'header'=> Yii::t('common', 'page'),
            'attribute' => 'page',
        ],
        [
            'header'=> Yii::t('common', 'referer_url'),
            'attribute' => 'referer_url',
        ],
        [
            'header'=> Yii::t('common', 'access_url'),
            'attribute' => 'access_url',
        ],
        [
            'header'=> Yii::t('common', 'method'),
            'attribute' => 'method',
        ],
        [
            'header'=> Yii::t('common', 'sess_id'),
            'attribute' => 'sess_id',
        ],
        [
            'header'=> Yii::t('common', 'created_by'),
            'attribute' => 'created_by',
        ],
        [
            'header'=> Yii::t('common', 'created_at'),
            'attribute' => 'created_at',
        ],
        [
            'header'=> Yii::t('common', 'created_ip'),
            'attribute' => 'created_ip',
        ],
        [
            'class' => 'kartik\grid\ActionColumn',
            'header' => Yii::t('common', 'operation_button'),
            'template' => '{delete}',
            'width' => '80px',
            'buttons' => [
            ],
        ],
    ];

    $contentName = Yii::t('common', 'log');

    $addbtn = '';
    if(Helper::checkRoute('create')) {
        //$addbtn = Html::a(Yii::t('common', 'create_{modelClass}', ['modelClass' => Yii::t('common', 'ad'),]), ['create'], ['class' => 'btn btn-default greenBtn']);
    }

    $form = ActiveForm::begin([
        'id' => 'list-form'
    ]);

    echo TGridView::widget([
        'id'=>'grid',
        'dataProvider' => $dataProvider,
        //'filterModel' => $searchModel,
        'columns' => $gridColumns,
        'panel' => [
            'type' => TGridView::TYPE_DEFAULT,
            'heading' => '<h3 class="panel-title" style="text-align: left;"><i class="glyphicon glyphicon-book"></i> ' .Yii::t('common', '{value}_record', ['value'=>$contentName]).'</h3>',
        ],
        'toolbar' => [
            ['content'=>
                $addbtn
                .' '.
                (TStringHelper::canBeModified() ? Html::button('<i class="glyphicon glyphicon-minus"></i> '.Yii::t('common', 'batch_delete_button'),['title'=>Yii::t('common', 'batch_delete_button'), 'class'=>'btn btn-default redBtn', 'onclick' => 'batchDeleteBtn("'.Yii::$app->urlManager->createUrl(['log/batch-delete']).'")']) : ''),
            ],
//            '{export}',
//            '{toggleData}'
        ],
        'pjax'=> false,
        'pjaxSettings'=>[
            'neverTimeout'=>true,
        ]
    ]);

    ActiveForm::end();
    ?>
    <div class="text-left">
        <?php
        echo \yii\widgets\LinkPager::widget([
            'id' => 'log_page',
            'pagination'=>$dataProvider->pagination,
        ]);
        ?>
    </div>
</div>

<script>
    function loadList() {
        location.reload();
    }
</script>
